home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FishMarket 1.0
/
FishMarket v1.0.iso
/
fishies
/
326-350
/
disk_342
/
sksh
/
view.doc
< prev
next >
Wrap
Text File
|
1992-05-06
|
12KB
|
331 lines
"view" - A File Type Encapsulator
SKsh
A ksh-like Shell for the Amiga
Version 1.4
(Copyright) 1989, 1990
Steve Koren
March 19, 1990
Introduction
"view" is a program which attempts to determine the
logical type of a file and deal with it appropriately in
a user definable way. It is actually an extension of
the "file" command found on many Un*x systems and will
emulate the function of that command if desired.
"view" assumes that files come in types; for example,
some files are plain ascii text, some are IFF picture files,
some are ANIM files, some are zoo files or arc files, etc.
Each of these file types has a given operation that is
commonly performed on it. You might "more" a text file,
"xd" binary data, and "show" a picture file:
[dh0:]: more mydoc.txt
[dh0:]: show mypic.ham
[dh0:]: xd mydata
[dh0:]: zoo -list myarchive.zoo
[dh0:]: arc -v myarchive.arc
[dh0:]: showanim -C myanim.anim
Using "view" (which is best aliased to "v"), all of the
above can be performed as:
[dh0:]: v mydoc.txt
[dh0:]: v mypic.ham
[dh0:]: v mydata
[dh0:]: v myarchive.zoo
[dh0:]: v myarchive.arc
[dh0:]: v myanim.anim
View saves you from having to remember how to deal with
each kind of file (if you have ever accidentally "catted" a
binary file, you will know why this is valuable). It
provides much the same functionality as the "default
tool" concept from workbench; you can just view a file,
and be assured that something logical will happen. You
can think of it as a "more" command that can cope with
more than just text files.
"view" is also extensible; it can handle several
different methods for determining the type of a file, new
types can be added at will, and user definable actions can
be added.
The disadvantage of "view" is that it requires some
initial setup that must be done on a system specific basis;
everyone has their favorite text and picture viewers, etc, and
everyone has them in different places. However, once
this initial configuration is done, it won't change
frequently.
SKsh Amiga Shell Page 2 View Manual
View will perform a few other services for you as well;
these will be explained later.
How View Works
When view begins execution, it loads a "magic" file into
memory. This magic file contains information on the various
file types and the actions that are associated with each file
type. It can be located anywhere, since it is referenced
through a "vmagic:" assignment, but it is best copied to a ram
disk in your startup sequence. This will allow view to
operation as fast as possible. In the best Un*x tradition,
this file is cryptic, nearly unreadable, and unforgiving of
format errors, but it is read by view fairly quickly.
View supports several methods of determining a file's type:
* The OFFSET method allows view to determine a file's type
from a fixed sequence of bytes that is located at a given
place in the file. The OFFSET type is used to find 'zoo'
files, for example. It is also reliable; if the zoo file
is renamed to end with ".arc", the OFFSET method will
still properly identify the file as a zoo archive.
* The WORDS method allows view to look for certain key words
in a file. For example, view uses this method to find 'c'
code and English text.
* The SUFFIX method determines file type based upon the file
name. This is not always reliable, but it works if your
files have a naming convention. For example, if all your
lharc files end with ".lzh", you can use the SUFFIX method
to find them.
* The CHARS method allows file time to be determined based
upon the characters in a file. For example, ASCII text
files might contain the characters 0x20 to 0x7f.
A special DIRECTORY method is used to identify directories.
Since directories are not files per se under AmigaDos, this
method is somewhat of a special case. (NOTE: the DIRECTORY
method is not yet implemented in this release of view).
The Format of the Magic File
The magic file contains colon (":") separated records, one per
line. Each line is limited to 255 characters (and this is not
checked for by view, so it would be advisable to stay under
this limit). Lines may be empty if their only character is a
newline, and a "#" in the first character of a line causes
view to ignore the rest of the line. The first record of a
line is a type name, which may contain any ASCII character
except a colon. The second is a keyword, and must be exactly
SKsh Amiga Shell Page 3 View Manual
one of:
OFFSET, WORDS, SUFFIX, CHARS, DIRECTORY, ACTION, DEFAULT
View will complain if the second file does not contain one of
the above values (which must be in upper case). The third and
fourth fields are data fields, and their interpretation
depends on the contents of the second field.
As an example, here are a few lines from my magic file:
zoo archive:OFFSET:20:dca7c4fd
IFF ilbm file:OFFSET:0:464f524d........494c424d424d4844
c source:WORDS:5:include ,define ,/*,*/,int ,char , printf
object file:SUFFIX::.o
ascii text:CHARS::20-7f
zoo archive:ACTION::sys:usr/bin/zoo -list %s
IFF ilbm file:ACTION::sys:bin/show %s
object file:ACTION::sys:usr/local/bin/xd %s
all:DEFAULT::c:more %s
My actual magic file is about 3 times that large, but this
subset will suffice for an example. The lines may come in any
order.
The first line identifies a zoo archive. The first field is
the type name (which is arbitrary). The second indicates that
view should use the OFFSET method. The third field is a
decimal integer less than 1023 which tells view where it
should start checking the file contents. The fourth field is
a sequence of characters, which, when taken in pairs, identify
hexadecimal byte values. They may optionally be separated by
commas for readability. In this example, view will move to
the spot 20 bytes from the beginning of the file, and examine
the next four bytes for the indicated values. If the bytes
match exactly, view assumes the file is a zoo file.
The second line is almost like the first, but it illustrates
that bytes may be skipped ("don't care" values). Two dots
will skip one byte in the file.
The third line uses the WORDS method. In my actual file,
there are more identifying words, but this will suffice as an
example. The third field is a decimal integer representing
the number of keywords that must be found in the first 1024
bytes of the file for view to assume that the file is of the
given type. For example, it may attempt to tell c source code
from English text from a SKsh script file. In this case, 5 of
the keywords must be found. The fourth field contains a comma
separated list of keywords. Spaces are significant and must
be matched exactly (notice the spaces after some of the
SKsh Amiga Shell Page 4 View Manual
keywords).
The fourth line identifies an object file by its suffix. The
suffix should include any "." and must be in the fourth field,
not the third.
Three ACTION lines follow the type definitions. Each one must
begin with the name of a type, the second field must be
ACTION, and the fourth must be a string to be executed. If
the string contains a "%s", this will be replaced with the
name of the current file. The fourth field in an ACTION line
may itself contain a colon, which is useful for path names. It
is best to supply the full path name to a utility program for
fast lookup, and it is necessary if the program is not in your
AmigaDos path.
The last line is a DEFAULT line. If a type is found (such as
for c source code), and no corresponding ACTION line is found,
the action from the last field of the DEFAULT line is used.
This is usually something like "more", "less" or your favorite
text reader. An empty ACTION statement will override the
DEFAULT line.
You can put your own data types and actions in this file.
Using view
First of all, it is best to alias view to something very
short. Also, the full path name can be put in the alias for
speed. Using SKsh, this can be accomplished as follows:
alias v=sys:usr/local/bin/view
(substitute the path to the view binary on your own system).
Also, you must assign "vmagic:" to the magic file. It is best
to copy the magic file to a ram disk in your startup-sequence;
the file is small, and having it there will greatly speed
view.
There are several options for view:
view -v prints the version of view
view -t file ... prints the type of each file passed to
view.
view -type file ... same as above
view file ... uses the action for each file type.
SKsh Amiga Shell Page 5 View Manual